package name.mrzc.licensing.controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import name.mrzc.licensing.model.License;
import name.mrzc.licensing.services.LicenseService;

@RestController
@RequestMapping(value = "v1/ORGs/{orgID}/licenses")
public class LicenseController {
	@Autowired
	private LicenseService licenseService;

	@RequestMapping(value = "/", method = RequestMethod.GET)
	public List<License> getLicenses(@PathVariable("orgID") String organizationId) {
		return licenseService.getLicensesByOrg(organizationId);
	}

	@RequestMapping(value = "/{licenseID}", method = RequestMethod.GET)
	public License getLicense(@PathVariable String orgID, @PathVariable String licenseID) {
		return License.builder().licenseId(licenseID).productName("Teleco").licenseType("Seat4").organizationId(orgID)
				.build();
	}

	@RequestMapping(value = "/", method = RequestMethod.POST)
	public void saveLicenses(@RequestBody License license) {
		licenseService.saveLicense(license);
	}

}
